home *** CD-ROM | disk | FTP | other *** search
- /*
- | file name -- FDSRandom.c
- |===================================================================
- |
- | Example for Function DataSource Function Descriptors.
- |
- | InitRandom() init function - has one argument, the seed
- | ReadRandom() read function - does nothing
- | TermRandom() term function - does nothing
- | SelectRandom() select function - has two arguments specifying
- | the range of the data
- |
- |===================================================================
- */
-
- #ifndef lint
- static char *SccsId = "@(#)FDSrandom.c V1.25 3/13/95";
- #endif
-
- #include "std.h"
- #include "dvfds.h"
- #include "dvtools.h"
- #include "Tfundecl.h"
- #include "VUfundecl.h"
-
- /***************** Begin Function Declarations *************/
- LOCAL LONG InitRandom V_P_((LONG seed));
- LOCAL LONG ReadRandom V_P_((void));
- LOCAL LONG TermRandom V_P_((void));
- LOCAL LONG CharSelectRandom V_P_((double *minval, double *maxval));
- LOCAL LONG ShortSelectRandom V_P_((double *minval, double *maxval));
- LOCAL LONG LongSelectRandom V_P_((double *minval, double *maxval));
- LOCAL LONG FloatSelectRandom V_P_((double *minval, double *maxval));
- LOCAL LONG DoubleSelectRandom V_P_((double *minval, double *maxval));
- LOCAL LONG MatrixSelectRandom V_P_((double *minval, double *maxval));
- /***************** End Function Declarations *************/
-
- /* This module uses two external routines, VUsrand() and VUfrand(),
- which compose random number genertor module.
- VUsrand sets the random number generator seed and VUfrand returns
- a random floating point number in the range [0,1].
- */
-
- LOCAL LONG
- InitRandom (seed)
- LONG seed;
- {
- VUsrand (seed);
- return DV_SUCCESS;
- }
-
- LOCAL LONG ReadRandom
- V_P_ ((void))
- {
- return DV_SUCCESS;
- }
-
- LOCAL LONG TermRandom
- V_P_ ((void))
- {
- return DV_SUCCESS;
- }
-
- LOCAL LONG
- CharSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- CHAR d;
-
- d = *minval + (*maxval - *minval) * VUfrand ();
- TdsvSetTypedValue (M_dsvcurrent, V_C_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
- return DV_SUCCESS;
- }
-
-
- LOCAL LONG
- ShortSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- SHORT d;
- d = *minval + (*maxval - *minval) * VUfrand ();
- TdsvSetTypedValue (M_dsvcurrent, V_S_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
- return DV_SUCCESS;
- }
-
-
- LOCAL LONG
- LongSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- LONG d;
- d = *minval + (*maxval - *minval) * VUfrand ();
- TdsvSetTypedValue (M_dsvcurrent, V_L_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
- return DV_SUCCESS;
- }
-
-
- LOCAL LONG
- FloatSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- FLOAT d;
- d = *minval + (*maxval - *minval) * VUfrand ();
- TdsvSetTypedValue (M_dsvcurrent, V_F_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
- return DV_SUCCESS;
- }
-
-
- LOCAL LONG
- DoubleSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- DOUBLE d;
- d = *minval + (*maxval - *minval) * VUfrand ();
- TdsvSetTypedValue (M_dsvcurrent, V_D_TYPE, (ADDRESS) & d, (INT) 0, (INT) 0);
- return DV_SUCCESS;
- }
-
- LOCAL LONG
- MatrixSelectRandom (minval, maxval)
- double *minval;
- double *maxval;
- {
- FLOAT s;
- INT j;
- INT rows, cols, num_elements;
-
- TdsvGetSize (M_dsvcurrent, &rows, &cols);
- num_elements = rows * cols;
- for (j = 0; j < num_elements; j++)
- {
- s = VUfrand ();
- s = *minval + (*maxval - *minval) * s;
- TdsvSetTypedValue (M_dsvcurrent, V_F_TYPE, (ADDRESS) & s,
- (LONG) 0, (LONG) j);
- }
- return DV_SUCCESS;
- }
-
- V_FDS_FCN_DECL (V_FDS_FCN_OPEN, FD_InitRandom,
- InitRandom, "Set random # seed")
- V_FDS_LONG_ARG_DECL ("seed", 654321)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_CLOSE, FD_TermRandom, TermRandom, "Terminate")
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_READ, FD_ReadRandom, ReadRandom, "Read")
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_CharSelectRandom,
- CharSelectRandom, "Get byte random datum")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_ShortSelectRandom,
- ShortSelectRandom, "Get word random datum")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_LongSelectRandom,
- LongSelectRandom, "Get long random datum")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_FloatSelectRandom,
- FloatSelectRandom, "Get float random datum")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_DoubleSelectRandom,
- DoubleSelectRandom, "Get double random datum")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 100.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_FCN_DECL (V_FDS_FCN_SELECT, FD_MatrixSelectRandom,
- MatrixSelectRandom, "Random data for matrix variables")
- V_FDS_DOUBLE_ARG_DECL ("Minimum Value", 0.0)
- V_FDS_DOUBLE_ARG_DECL ("Maximum Value", 1.0)
- V_FDS_END_FCN_DECL
-
- V_FDS_START_DECL (FDSrandom)
- V_FDS_FCN_DEFINED (FD_InitRandom)
- V_FDS_FCN_DEFINED (FD_TermRandom)
- V_FDS_FCN_DEFINED (FD_ReadRandom)
- V_FDS_FCN_DEFINED (FD_CharSelectRandom)
- V_FDS_FCN_DEFINED (FD_ShortSelectRandom)
- V_FDS_FCN_DEFINED (FD_LongSelectRandom)
- V_FDS_FCN_DEFINED (FD_FloatSelectRandom)
- V_FDS_FCN_DEFINED (FD_DoubleSelectRandom)
- V_FDS_FCN_DEFINED (FD_MatrixSelectRandom)
- V_FDS_END_DECL
-
-
-
-
-
-
-